<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="./appframework.min.js"></script>
<script type="text/javascript" charset="utf-8" src="./js/base.js"></script>
<meta charset="UTF-8">
<title>心愿墙</title>
<script type="text/javascript">
$(document).ready(function(){
	if("" == wechatIdStr){
		var parm = getRequestParam();
		if((parm["code"] !=undefined && parm["code"] !="")){
			queryWechatInfo(parm["code"]);
		}
	}
	if("" != wechatIdStr){//根据openid判断订单是否存在
		$.ajax({ 
	        type: "get",
	        async: false, 
	        url: baseUrl + "/json/wishwall/wishOrder_queryWishOrderByWechatId", 
	        dataType: "json", 
	        data: "wechatId=" + wechatIdStr + "&programCode="+programCodeVal,
	        error: function (XMLHttpRequest, textStatus, errorThrown) { 
	        	alert("error!");
	            alert(errorThrown); 
	        },
	        success: function (data) {
	        	if(null != data.id && undefined != data.id && "" != data.id){
	        		var url = escape(baseUrl+"/html/index.html?wishOrderId="+data.id+"&type=fenxiang");
	        		window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc053aefd1dfd9fc1&redirect_uri="+url+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
	        	}else{
	        		alert("您还没有许愿单，请立即许愿。");
	        		window.location.href = baseUrl + "/html/index.html#main";
	        	}
	        } 
		});
	}
});

function queryWechatInfo(code){
	$.ajax({ 
        type: "POST",
        async: false, 
        url: baseUrl + "/json/wishwall/wishOrder_checkIsGuanzhu", 
        dataType: "json", 
        data : "code="+code+"&openId="+wechatIdStr,
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
            alert("error!"+errorThrown); 
        },
        success: function (data) {
        	if(data.state == '1'){
        		wechatIdStr = data.openId;
        		subscribeStr = data.subscribe;
        		wecharNameVal = data.nickName;
        	}else if(data.state == '0'){
        		alert("faile!");
        	}
        }
	});
}
</script>
</head>
<body>
	<span id = "id_wishOrderNotFound"></span>
</body>
</html>